package com.example.administrator.nurse.present;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.nurse.R;
import com.example.administrator.nurse.base.BaseActivity;
import com.example.administrator.nurse.model.CommonViewHolder;
import com.example.administrator.nurse.model.RecyclerViewCommonAdapter;
import com.example.administrator.nurse.model.bean.money_check_bean;
import com.example.administrator.nurse.util.recyclerViewHelper;
import com.example.administrator.nurse.widget.ItemImage;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/24.
 *
 */

public class BodyCheckActivity extends BaseActivity {

    private List<money_check_bean> list = new ArrayList<>();
    private recyclerViewHelper<money_check_bean> recyclerViewHelper;
    private RecyclerViewCommonAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        configCommonHeader(BodyCheckActivity.this, "体检报告", 1);
        initView();
    }

    @Override
    protected int setLayotId() {
        return R.layout.body_check_main;
    }

    @Override
    protected void onFailure(int requestCode, Object object, String errorMsg) {

    }

    @Override
    protected void onSuccess(int requestCode, Object object, String response) {

    }

    private void initView() {

        LinearLayout itemImageContainer = (LinearLayout) f(R.id.imageItemContainer);
        itemImageContainer.addView(
                new ItemImage(this, itemImageContainer)
                        .withImageSrc(R.drawable.xindiantu)
                        .withTvText("心电图").init()
        );

        itemImageContainer.addView(
                new ItemImage(this, itemImageContainer)
                        .withImageSrc(R.drawable.bchao)
                        .withTvText("B超").init()
        );

        itemImageContainer.addView(
                new ItemImage(this, itemImageContainer)
                        .withImageSrc(R.drawable.ct)
                        .withTvText("CT").init()
        );

        itemImageContainer.addView(
                new ItemImage(this, itemImageContainer)
                        .withImageSrc(R.drawable.normal)
                        .withTvText("普放").init()
        );

        itemImageContainer.addView(
                new ItemImage(this, itemImageContainer)
                        .withImageSrc(R.drawable.cigongzhen)
                        .withTvText("磁共振").init()
        );

        itemImageContainer.addView(
                new ItemImage(this, itemImageContainer)
                        .withImageSrc(R.drawable.liver)
                        .withTvText("肝功能").init()
        );

        recyclerViewHelper = new recyclerViewHelper<money_check_bean>(this, (XRecyclerView) findViewById(R.id.recyclerView))
                .withAdapter(R.layout.body_check_bean)
                .withTestData(new recyclerViewHelper.TestDataInterface() {
                    @Override
                    public money_check_bean addTestData(int i) {
                        money_check_bean bean = new money_check_bean();

                        bean.setAreaNum("0" + i);
                        bean.setBed("0" + i);
                        bean.setName("林冠宏");
                        bean.setAge("91岁");
                        bean.setSex("男");

                        return bean;
                    }
                })
                .withBindView(new recyclerViewHelper.BindViewListener() {
                    @Override
                    public void bindView(CommonViewHolder holder,final int position) {
                        holder.getConvertView().setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent(BodyCheckActivity.this,BodyCheckItemActivity.class);
                                intent.putExtra("data", (Serializable) recyclerViewHelper.list.get(position));
                                startActivity(intent);
                            }
                        });

                        TextView info, number, status;
                        info = holder.getTextView(R.id.info);
                        number = holder.getTextView(R.id.number);

                        info.setText(
                                recyclerViewHelper.list.get(position).getName() + "," +
                                        recyclerViewHelper.list.get(position).getSex() + "," +
                                        recyclerViewHelper.list.get(position).getAge());
                        number.setText("病区号:" +
                                recyclerViewHelper.list.get(position).getArea() + " 病房号:" +
                                recyclerViewHelper.list.get(position).getBed());

                        /** 状态在下面显示 */
                        status = holder.getTextView(R.id.status);
                        //status.setText("已出院");
                    }
                })
                .withLoadMore(new recyclerViewHelper.loadMoreListener() {
                    @Override
                    public void loadMore() {

                    }
                });
        recyclerViewHelper.initRecyclerView();
    }


}
